package com.hnevc.yourhealthmanager.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnevc.yourhealthmanager.dto.DietRecordDTO;
import com.hnevc.yourhealthmanager.entity.DietRecord;
import com.hnevc.yourhealthmanager.entity.HealthPlane;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DietRecordMapper extends BaseMapper<DietRecord> {
    
    @Select("select drt.id,user_id,username,food_id,food_name,diet_category_id,diet_category_name,diet_image,diet_time " +
            "from diet_record_table as drt, health_user_table as hut , food_meta_table as fmt, diet_category_table as dct " +
            "where drt.food_id = fmt.id and drt.user_id = hut.id and drt.diet_category_id = dct.id and user_id = #{userId}")
    List<DietRecordDTO> selectDietRecordByUserId(@Param("userId") Integer userId);

    @Select("select drt.id,user_id,username,food_id,food_name,diet_category_id,diet_category_name,diet_image,diet_time " +
            "from diet_record_table as drt, health_user_table as hut , food_meta_table as fmt, diet_category_table as dct " +
            "where drt.food_id = fmt.id and drt.user_id = hut.id and drt.diet_category_id = dct.id and user_id = #{healthPlane.userId} " +
            "and diet_time between #{healthPlane.startDate} and #{healthPlane.endDate} ")
    List<DietRecordDTO> getDietRecordListByHealthPlane(@Param("healthPlane") HealthPlane healthPlane);

    @Select("select drt.id,user_id,username,food_id,food_name,diet_category_id,diet_category_name,diet_image,diet_time " +
            "from diet_record_table as drt, health_user_table as hut , food_meta_table as fmt, diet_category_table as dct " +
            "where drt.food_id = fmt.id and drt.user_id = hut.id and drt.diet_category_id = dct.id and user_id = #{healthPlane.userId} " +
            "and diet_time between #{healthPlane.startDate} and #{healthPlane.endDate}  " +
            "and Month(diet_time)=#{month} and Year(diet_time)=#{year}")
    List<DietRecordDTO> getDietRecordListByPlaneMonth(@Param("healthPlane") HealthPlane healthPlane,@Param("month") Integer month ,@Param("year") Integer year);


}